/**
 * 
 */
package org.bspv.pharma.web.bean.node.visitor;

import java.util.Map;

import org.bspv.pharma.web.bean.node.Node;
import org.bspv.pharma.web.bean.node.TypeNode;

/**
 * @author guillaume
 *
 */
public class TypeToHtmlVisitor extends AbstractVisitor {

	public String visit(Node node, Map<String, String> params) {
		StringBuilder sb = new StringBuilder();
		// ouverture
		TypeNode currentNode = (TypeNode) node;
		sb.append("<li>");
		sb.append("<span class=\"typeNode ");
		sb.append(currentNode.getStockStatus()==null?"":currentNode.getStockStatus().getName());
		sb.append("\">");
		sb.append(node.toString());
		sb.append("<span class=\"statusTooltip\">(");
		sb.append(currentNode.getNbSupplies());
		sb.append("/");
		sb.append(currentNode.getNbSuppliesExpected());
		sb.append(")</span></span>");
		
		boolean children = false;
		if(node.getChildren() != null && node.getChildren().size()>0) {
			sb.append("<ul name=\"");
			sb.append(node.getName());
			sb.append("\"_children>");
			children = true;
		}
		for (Node child : node.getChildren()) {
			sb.append(VisitorManager.getVisitor(child.getClass()).visit(child, params));
		}
		if(children) {
			sb.append("</ul>");
		}
		// fermeture
		sb.append("</li>");
		return sb.toString();
	}
	
}
